<template>
  <div class="app-container">
    <el-form :model="queryParam" ref="queryForm" size="small" :inline="true"  label-width="68px">
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParam.username"
          placeholder="请输入用户名"
          clearable
          style="width: 240px"
          @keyup.enter.native="btnSearch"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParam.status"
          placeholder="字典状态"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dicts.sys_normal_disable"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="btnSearch">搜索</el-button>
      </el-form-item>
    </el-form>


    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPerm="['system:user:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPerm="['system:user:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPerm="['system:user:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPerm="['system:user:export']"
        >导出</el-button>
      </el-col>
    </el-row>


    <el-table :data="tableData.rows" border style="width: 100%" @selection-change="handleSelectionChange">
       <el-table-column type="selection" width="55" align="center"  :selectable="selectable" />
       <el-table-column label="用户编号" width="80"  align="center" prop="userId" />
       <el-table-column label="用户名称"   align="center" prop="username" :show-overflow-tooltip="true" />
       <el-table-column label="邮箱" prop="email"   align="left" :show-overflow-tooltip="true" />
       <el-table-column label="手机" prop="mobile"  align="center" :show-overflow-tooltip="true" />

       <el-table-column label="状态" align="center" prop="status">
         <template slot-scope="scope">
            <DictTag :dataArray="dicts.sys_normal_disable" :value="scope.row.status"></DictTag>
         </template>
       </el-table-column>

       <el-table-column label="创建时间" align="center" prop="createTime" width="180"></el-table-column>
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
             v-if="scope.row.userId!==1"
             size="mini"
             type="text"
             icon="el-icon-edit"
             @click="handleUpdate(scope.row)"
             v-hasPerm="['system:user:edit']"
           >修改</el-button>
           <el-button
             v-if="scope.row.userId!==1"
             size="mini"
             type="text"
             icon="el-icon-delete"
             @click="handleDelete(scope.row)"
             v-hasPerm="['system:user:remove']"
           >删除</el-button>
         </template>
       </el-table-column>
     </el-table>

    <el-pagination v-if="tableData.total>0" :current-page="queryParam.page" :page-sizes="[10, 20,30,50]"
      :page-size="queryParam.size" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" />

  </div>
</template>

<script>
  import {dataListApi, addApi, editApi,deleteApi, findByIdApi,} from '@/api/user.js'
  import PageMinix from '@/mixin/PageMixin.js'
  import AddOrEditMixin from '@/mixin/AddOrEditMixin.js'
  import DictDataMinix from '@/mixin/DictDataMinix.js'
  export default {
    mixins: [DictDataMinix, PageMinix, AddOrEditMixin],
    dicts: ['sys_normal_disable'],
    data() {
      return {
        fetchDataApi: dataListApi,
        addApi: addApi,
        editApi: editApi,
        deleteByIdApi: deleteApi,
        findByIdApi: findByIdApi,
        primaryKey: 'userId',
        // 表单校验
        rules: {
          username: [
            { required: true, message: "用户名称不能为空", trigger: "blur" }
          ],
          email: [
            { required: true, message: "邮箱不能为空", trigger: "blur" }
          ]
        }
      }
    },
    methods: {
     initFormValue() {
       this.form = {
         status: '0'
       }
     },
     // 导出excel
     handleExport(){

     },
     // 是否可以选中表格的列
     selectable(row ,index){
       return row.userId!==1
     }

    },
    created(){
      this.initFormValue()
    }
  }
</script>
<style>
</style>
